using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Abs.Core.Models.Blog;
using Abs.Core.Models.Booking;
using Abs.Core.Util;

namespace Abs.Core.Models.User
{
    public enum UserField
    {
        Email = 0,
        Name,
        Password, 
        RoleId
    }//end of public enum UserField

    public class User
    {
        //private field
        private int roleId = (int) RoleEnum.User;
        private string password;

        //Properties
        [Required(ErrorMessage = "Name is required.")]
        public string Name { get; set; }

        [Required(ErrorMessage = "Password is required")]
        [DataType(DataType.Password)]
        [MinLength(6, ErrorMessage = "Minimum length is 6.")]
        public string Password 
        { 
            get
            {
                return this.password;
            }
            set
            {
                this.password = Sha512.Hashing(value);
            }
        }//end of public virtual string Password 

        [Required(ErrorMessage = "E-mail is required.")]
        [DataType(DataType.EmailAddress)]
        [EmailValidation (ErrorMessage = "E-mail has to be valid.")]
        [Key]
        public string Email { get; set; }

        [ForeignKey("Role")]
        public virtual int RoleId
        {
            get { return this.roleId; }
            set { this.roleId = value; }
        }
        public Role Role { get; set; }

        public ICollection<Appointment> Appointments { get; set; }

        public ICollection<Post> Posts { get; set; }

        public ICollection<Comment> Comments { get; set; } 
    }//end of public class UserManagement
}//end of namespace ABS.Models